package cn.scau.edu.software.lgh.service;

import cn.scau.edu.software.lgh.entity.NetWork;
import cn.scau.edu.software.lgh.entity.Route;

import java.util.Vector;

public class NetworkSecviceImpl {


    /**
     * 生成一个网络
     * @param networkId
     * @return
     */
    public static NetWork createNetwork(String networkId){
        return new NetWork(networkId);
    }

    /**
     * 指定network连接已存在的route
     * @param netWork 指定
     * @param route
     * @return
     */
    public static boolean addRouteToNetwork(NetWork netWork,Route route){
        if(netWork.getLinkedRoutes().add(route)){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 接收路由器发送的更新信息，network负责传递
     * @param route 来自哪个路由器发送的路由信息
     * @param netWork 发送到哪个network，向它所连的route(除了发送信息的路由器外)发送路由更新信息
     */
    public static void getUpdataMessage(Route route,NetWork netWork,Vector<Route> flowedThroughRoute){
        Vector<Route> routes = netWork.getLinkedRoutes();
        for(Route router:routes){
            if(flowedThroughRoute.indexOf(router)==-1){
                RouteServiceImpl.getUpdataMessageOfNetwork(route,router,netWork,flowedThroughRoute);
            }
        }

    }

}
